package com.realgodo.site.web.user.friend;

import org.apache.struts2.convention.annotation.Result;
import org.springframework.context.annotation.Scope;

import com.realgodo.site.entity.relation.FriendCatalog;



/**朋友分类管理*/
@Scope("prototype")
@Result(name = IndexController.TO_INDEX, type = "redirect", location = "${base}/user/friend/catalog")
public class CatalogController extends IndexController {
	
	/***/
	private static final long serialVersionUID = 9177526532559243748L;
	
	private String name;
	
	@Override
	public String execute() throws Exception {
		return list();
	}
	
	public String index(){
		return list();
	}

	public String list(){
		friendCatalogList=friendCatalogManager.getFriendCatalogList(super.getSpace().getId());
		return SUCCESS;
	}
	
	/**保存/编辑朋友*/
	public String save(){
		FriendCatalog friendCatalog=null;
		if(super.catalogId==null){
			friendCatalog=new FriendCatalog();
		}else{
			friendCatalog=friendCatalogManager.get(catalogId);
		}
		friendCatalog.setName(name);
		friendCatalog.setSpace(getSpace());
		friendCatalogManager.save(friendCatalog);
		return TO_INDEX;
	}
	
	/**删除朋友分组*/
	public String delete(){
		if(super.catalogId==null){
			return SUCCESS;
		}
		friendCatalogManager.delete(super.getSpace().getId(), catalogId);
		return TO_INDEX;
	}
	//------get/set---------//
	@Override
	public int getIsManagerCatalog() {
		return 1;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	
}
